package com.zy.cat.common.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.zy.cat.entity.game.resp.Prize;

/**
 * 
 * @Description: 游戏抽奖概率设置
 * @author xiake
 * @date 2020-10-27 10:07:44
 */
public class DrawProportionUtil {

	//大转盘
	private static final Map<Integer, Map<String,Object>> turnUserMap=new HashMap<Integer, Map<String,Object>>();
	
	//刮刮卡新用户
	private static final Map<Integer, Map<String,Object>> cardUserMap=new HashMap<Integer, Map<String,Object>>();
	
	//新用户任务完成金豆数量
	public static final int NEW_USER_TASK_BAENS_NUM=1200;
	
	/**
	 * 获取大转盘抽奖概率配置信息实例
	 * @author lipengchao
	 * @date 2019-12-05 01:40:10
	 * @param level 用户等级分类0.新用户、1.正常用户
	 * @return
	 */
	public static Map<String,Object> getTurnInstance (int level) {
		//如果为空则初始化
		if (turnUserMap.get(level)==null) {
			initTurnInstancePlus(level);
		}
		return turnUserMap.get(level);
	}
	
	/**
	 * 初始化大转盘概率
	 * @author lipengchao
	 * @date 2019-12-05 01:55:25
	 * @param level
	 */
	private static void initTurnInstance(int level) {
		Map<String,Object> turnMap=new HashMap<>();
		
		//奖品类型 0.现金豆、 1礼包(广告)
		turnMap.put("prizeTypeArr", new String[]{"0","1"});
		
		//广告类型 : 101.展示广告红包,102.互动广告红包
		turnMap.put("advertTypeArr", new String[]{"101","102"});
		
		//按钮类型： 0.领取礼包、1.继续游戏
		turnMap.put("btnTypeArr", new String[]{"0","1"});
		
		//获取金豆数量比重
		String[] beanArray= {"6-14","14-23","23-32","32-40"};
		turnMap.put("beanArray", beanArray);
		
		//新用户
		if (level==0) {
			//奖品类型 0.现金豆（占51）, 1礼包(广告)（占49）
			turnMap.put("prizeProportions", new double[]{51,49});
			//广告类型 : 101.展示广告红包（占21）,102.互动广告红包(占26)
			turnMap.put("advertProportions", new double[]{21,26});
			//按钮类型： 0.领取礼包(19)、1.继续游戏(32)
			turnMap.put("btnProportions", new double[]{19,32});
			//获取金豆数量比重,现金豆总数约1084
			turnMap.put("beanProportions", new double[]{12,50,28,10});
			
		}else if(level==1 || level==-1){
			//正常用户
			//奖品类型 0.现金豆（占52）, 1礼包(广告)（占48）
			turnMap.put("prizeProportions", new double[]{52,48});
			//广告类型 : 101.展示广告红包（占17）,102.互动广告红包(占31)
			turnMap.put("advertProportions", new double[]{17,31});
			//按钮类型： 0.领取礼包(23)、1.继续游戏(29)
			turnMap.put("btnProportions", new double[]{23,29});
			//获取金豆数量比重,现金豆总数约975
			turnMap.put("beanProportions", new double[]{17,64,13,6});
		}else {
			return;
		}
		turnUserMap.put(level, turnMap);
	}
	
	
	/**
	 * 初始化大转盘概率
	 * @author lipengchao
	 * @date 2019-12-05 01:55:25
	 * @param level
	 */
	private static void initTurnInstancePlus(int level) {
		Map<String,Object> turnMap=new HashMap<>();
		
		//奖品类型 0.现金豆、 1礼包(广告)
		String[] prizeTypeArr= {"0","1"};
		//奖品类型 0.现金豆（占51）, 1礼包(广告)（占49）
		double[] prizeProportions=null;
		int[] prizeTypeCountArr=null;
		turnMap.put("prizeTypeArr", prizeTypeArr);
		
		//广告类型 : 101.展示广告红包,102.互动广告红包
		String[] advertTypeArr= {"101","102"};
		//广告类型 : 101.展示广告红包（占21）,102.互动广告红包(占26)
		double[] advertProportions=null;
		int[] advertTypeCountArr=null;
		
		//按钮类型： 0.领取礼包、1.继续游戏
		String[] btnTypeArr= {"0","1"};
		double[] btnProportions=null;
		int[] btnTypeCountArr=null;
		
		//获取金豆数量比重
		String[] beanArray= {"6-14","14-23","23-32","32-40"};
		turnMap.put("beanArray", beanArray);
		
		//新用户
		if (level==0) {
			//奖品类型 0.现金豆（占51）, 1礼包(广告)（占49）
			prizeProportions=new double[]{51,49};
			prizeTypeCountArr=new int[]{51,49};
			//广告类型 : 101.展示广告红包（占21）,102.互动广告红包(占26)
			advertProportions=new double[]{21,26};
			advertTypeCountArr=new int[]{21,26};
			//按钮类型： 0.领取礼包(19)、1.继续游戏(32)
			btnProportions=new double[]{19,32};
			btnTypeCountArr=new int[]{19,32};
			//获取金豆数量比重,现金豆总数约1084
			turnMap.put("beanProportions", new double[]{12,50,28,10});
			
		}else if(level==1 || level==-1){
			//正常用户
			//奖品类型 0.现金豆（占52）, 1礼包(广告)（占48）
			prizeProportions=new double[]{52,48};
			prizeTypeCountArr=new int[]{52,48};
			//广告类型 : 101.展示广告红包（占17）,102.互动广告红包(占31)
			advertProportions=new double[]{17,31};
			advertTypeCountArr=new int[]{17,31};
			//按钮类型： 0.领取礼包(23)、1.继续游戏(29)
			btnProportions=new double[]{23,29};
			btnTypeCountArr=new int[]{23,29};
			//获取金豆数量比重,现金豆总数约975
			turnMap.put("beanProportions", new double[]{17,64,13,6});
		}else {
			return;
		}
		
		/**
		 * 转盘抽奖抽取现金豆
		 */
		List<Prize> prizeList=CalculateUtil.getPrizeList(prizeTypeArr, prizeTypeCountArr, prizeProportions);
		
		List<Prize> advertTypeList=CalculateUtil.getPrizeList(advertTypeArr, advertTypeCountArr, advertProportions);
		
		List<Prize> btnTypeList=CalculateUtil.getPrizeList(btnTypeArr, btnTypeCountArr, btnProportions);
		
		turnMap.put("prizeList", JSON.toJSONString(prizeList));
		turnMap.put("advertTypeList", JSON.toJSONString(advertTypeList));
		turnMap.put("btnTypeList", JSON.toJSONString(btnTypeList));
		
		turnUserMap.put(level, turnMap);
	}
	
	/**
	 * 获取刮刮卡抽奖概率配置信息实例
	 * @author lipengchao
	 * @date 2019-12-05 01:40:10
	 * @param level 用户等级分类0.新用户、1.正常用户
	 * @return
	 */
	public static Map<String,Object> getCardInstance (int level) {
		//如果为空则初始化
		if (cardUserMap.get(level)==null) {
			Map<String,Object> cardturnMap=new HashMap<>();
			//刮刮卡中奖个数
			cardturnMap.put("fieldArray", new String[]{"1","2","3","4","5","6"});
			cardturnMap.put("beanNumArray", new int[] {5,20,50,80,200,300});
			//新用户
			if (level==0) {
				cardturnMap.put("proportions", new double[]{10,25,50,15,0,0});
			}else if (level==1 || level==-1) {
				cardturnMap.put("proportions", new double[]{0,35,10,50,5,0});
			}
			cardUserMap.put(level, cardturnMap);
		}
		return cardUserMap.get(level);
	}
	
	/**
	 * 获取刮刮卡抽奖概率配置信息实例
	 * @author lipengchao
	 * @date 2019-12-05 01:40:10
	 * @param level 用户等级分类0.新用户、1.正常用户
	 * @return
	 */
	public static Map<String,Object> getCardInstancePlus (int level) {
		//如果为空则初始化
		if (cardUserMap.get(level)==null) {
			Map<String,Object> cardturnMap=new HashMap<>();
			String[] fieldArray={"1","2","3","4","5","6"};
			int[] beanNumArray = new int[] {5,20,50,80,200,300};
			int bashNum=0;
			double[] proportion = null;
			int[] countArray=new int[fieldArray.length];
			//刮刮卡中奖个数
			cardturnMap.put("fieldArray", fieldArray);
			cardturnMap.put("beanNumArray", beanNumArray);
			//新用户
			if (level==0) {
				proportion=new double[]{0,13,12,68,30,0};
				cardturnMap.put("proportions", proportion);
				//设置基础数，一般要高于基础数
				bashNum=1200;
				cardturnMap.put("beanBaseNum", bashNum);
			}else if (level==1 || level==-1) {
				//正常用户，概率
				proportion=new double[]{2,20,42,25,30,0};
				cardturnMap.put("proportions", proportion);
				//设置基础数，一般要高于基础数
				bashNum=800;
				cardturnMap.put("beanBaseNum", bashNum);
			}
			//生成抽奖集合
			List<Prize> prizeList=new ArrayList<>();
			for (int i = 0; i < fieldArray.length; i++) {
				countArray[i]=proportion[i]==0?0:(int)(bashNum*(proportion[i]/100)/beanNumArray[i]);
				prizeList.add(new Prize(fieldArray[i], countArray[i], proportion[i]));
			}
			cardturnMap.put("prizeList", JSON.toJSONString(prizeList));
			cardUserMap.put(level, cardturnMap);
		}
		return cardUserMap.get(level);
	}
}
